

### Load Packages 
library(data.table)
library(ggplot2)
library(xtable)
library(stargazer)
library(DataCombine)
library(lfe)
library(foreign)
library(haven)
library(memisc)
library(readstata13)
library(mlogit)
library(nnet)
library(car)
library(erer)
library(margins)
library(interplot)
library(openxlsx)

rm(list=ls())

### Simple Functions

specify_decimal <- function(x, k) format(as.numeric(round(x, k), nsmall=k))

mod_stargazer <- function(est) {
  capture.output(est)
}

### Load 2016 RES Data (lev)

lev<-fread("RES_2016.csv")
names(lev)<-tolower(names(lev))

lev <- subset(lev,var==1)

lev[,male:=Recode(q135,"2=0")]
lev[,age:=2016-q136_god]
lev[,employed:=Recode(q31,"2=0")]
lev[,educ:=Recode(q137,"97=NA;98=NA")]
lev[,townsize:=Recode(tnp,"2=5;3=4;4=3;5=2;6=1;1=6")]
lev[,kpss:=Recode(q140,"2=0;7=0;8=0;NA=0")]
lev[,econ:=Recode(q144,"97=NA;98=NA")]

lev[,union:=ifelse(q152a==2,1,0)]
lev[,work:=ifelse(q152b==2,1,0)]
lev[,church:=ifelse(q152c==2,1,0)]
lev[,sport:=ifelse(q152d==2,1,0)]
lev[,music:=ifelse(q152e==2,1,0)]
lev[,ecology:=ifelse(q152f==2,1,0)]
lev[,prof:=ifelse(q152g==2,1,0)]
lev[,charity:=ifelse(q152h==2,1,0)]
lev[,youth:=ifelse(q152i==2,1,0)]

lev[,number_org:=union+work+church+sport+music+ecology+prof+charity+youth]

lev[,follow_pol:=Recode(q1,"7=NA;8=NA;4=1;3=2;2=3;1=4")]

lev[,putin_support:=Recode(q20,"7=NA;8=NA;5=1;4=2;2=4;1=5")]

lev[,ur_support:=Recode(q62,"97=NA;98=NA")]
lev[,URvote:=ifelse(q86==4,1,0)]
lev[q86==98 | q86==97 | q86==96,URvote:=NA]

lev[,elec_meaning:=Recode(q26,"7=NA;8=NA;5=1;4=2;2=4;1=5")]
lev[,elec_honest:=Recode(q27,"7=NA;8=NA;5=1;4=2;2=4;1=5")]
lev[,russia_democ:=Recode(q30,"7=NA;8=NA;2=0")]

lev[,accept_pensioner:=Recode(q51a,"7=NA;8=NA;4=1;3=2;2=3;1=4")]
lev[,accept_buy_rally:=Recode(q51b,"7=NA;8=NA;4=1;3=2;2=3;1=4")]
lev[,accept_attend:=Recode(q51c,"7=NA;8=NA;4=1;3=2;2=3;1=4")]
lev[,accept_wpthreat:=Recode(q51d,"7=NA;8=NA;4=1;3=2;2=3;1=4")]
lev[,accept_karusel:=Recode(q51e,"7=NA;8=NA;4=1;3=2;2=3;1=4")]
lev[,accept_restrict:=Recode(q51f,"7=NA;8=NA;4=1;3=2;2=3;1=4")]
lev[,accept_media:=Recode(q51g,"7=NA;8=NA;4=1;3=2;2=3;1=4")]

lev[,voted:=Recode(q77,"2=0;7=NA;8=NA")]

lev$log_age<-log(lev$age)

lev$elec_meaning=Recode(lev$q26,"7=NA;8=NA")

lev$exp_turnout=Recode(lev$q123a,"7=NA;8=NA;1=5;2=4;4=2;5=1")

lev$exp_turnout_dk=Recode(lev$q123a,"7=1;8=NA;1=0;2=0;3=0;4=0;5=0")

lev$exp_voteagainst=Recode(lev$q123a,"7=NA;8=NA;1=0;2=0;3=0;4=1;5=1")
lev$exp_votefor=Recode(lev$q123a,"7=NA;8=NA;1=1;2=1;3=0;4=0;5=0")
lev$exp_votemaybe=Recode(lev$q123a,"7=NA;8=NA;1=0;2=0;3=1;4=0;5=0")

lev$control<-ifelse(lev$variant_q123==12 | lev$variant_q123==8 | lev$variant_q123==4,1,0)
lev$fraud<-ifelse(lev$variant_q123==11 | lev$variant_q123==7 | lev$variant_q123==3,1,0)
lev$threat<-ifelse(lev$variant_q123==9 | lev$variant_q123==5 | lev$variant_q123==1,1,0)
lev$vote_buy<-ifelse(lev$variant_q123==10 | lev$variant_q123==6 | lev$variant_q123==2,1,0)

lev<-as.data.table(lev)
lev[control==1,full_fraud:=0]
lev[vote_buy==1,full_fraud:=1]
lev[fraud==1,full_fraud:=2]
lev[threat==1,full_fraud:=3]
lev$full_fraud<-as.factor(lev$full_fraud)
lev$any_fraud<-ifelse(lev$control==1,0,1)

lev$putin_honest<-car::Recode(lev$q100c,"1=4;2=3;3=2;4=1;7=NA;8=NA")

lev$putin_strong<-car::Recode(lev$q100b,"1=4;2=3;3=2;4=1;7=NA;8=NA")

lev$state_news<-ifelse(lev$first==1 | lev$ross==1 | lev$ntv==1,1,0)
lev$state_news[lev$q5==2 | lev$q4==2]<-0
lev$state_news[lev$q4==7| lev$q4==8|lev$q7a==7|lev$q7a==8|lev$q7b==7|lev$q7b==8|lev$q7c==7|lev$q7c==8]<-NA

lev$frequent_state_news<-lev$state_news
lev$frequent_state_news[lev$q6==3 | lev$q6==4]<-0

lev$internet2016_politics<-car::Recode(lev$q13a,"2=0;7=NA;8=NA")
lev$internet2016_politics[lev$q10==2]<-0

lev$internet_socialmedia<-car::Recode(lev$q11h,"2=0;7=NA;8=NA")
lev$internet_socialmedia[lev$q10==2]<-0

lev$internet_frequency<-car::Recode(lev$q14,"2=1;3=1;4=1;5=0;7=NA;8=NA")
lev$internet_frequency[lev$q10==2]<-0

lev$fb_twitter<-ifelse(lev$q12_3==1 | lev$q12_5==1 | lev$q12_4==1,1,0)
lev$fb_twitter[ lev$q10==2]<-0

lev$putin_support_demean<-lev$putin_support-mean(lev$putin_support,na.rm=TRUE)
lev$ur_support_demean<-lev$ur_support-mean(lev$ur_support,na.rm=TRUE)
lev$putin_honest_demean<-lev$putin_honest-mean(lev$putin_honest,na.rm=TRUE)
lev$putin_strong_demean<-lev$putin_strong-mean(lev$putin_strong,na.rm=TRUE)
lev$elec_honest_demean<-lev$elec_honest-mean(lev$elec_honest,na.rm=TRUE)

lev$real_choice=Recode(lev$q129b,"7=NA;8=NA")
lev$free_media=Recode(lev$q129c,"7=NA;8=NA")
lev$filtering=Recode(lev$q129d,"7=NA;8=NA")
lev$electoral_reforms=Recode(lev$q129e,"7=NA;8=NA")

### Load May 2018 Levada Data (levmay2018)

load("LevadaMay2018.Rda")

##################################
#######  MAIN TEXT     ###########
##################################

############   TABLES  ########################

###### TABLE 1

variables<-c("1. Attend opening ceremonies for cultural or sporting events during the month before elections",
             "2. Limit opposition candidates from appearing on television",
             "3. Create obstacles for opposition candidates to register",
             "4. Hand out food packets to pensioners",
             "5. Recruit people to attend political rallies with liquor or food",
             "6. Tell workers of a local firm that they will lose their jobs if they don't vote correctly",
             "7. Organize `carousels' by which buses shuttle people to vote at multiple polling stations")

table1<-as.data.frame(cbind(variables,round(rbind(prop.table(table(lev$accept_attend)),
                            prop.table(table(lev$accept_media)),
                            
                            prop.table(table(lev$accept_restrict)),
                            prop.table(table(lev$accept_pensioner)),
                            prop.table(table(lev$accept_buy_rally)),
                            prop.table(table(lev$accept_wpthreat)),
                            prop.table(table(lev$accept_karusel)) )*100,0)))

# write.csv(table1, file="Table1.csv",row.names = FALSE)

###### TABLE 2

lev$induce=" No Electoral Manipulation"
lev$induce[lev$fraud==1]="Organized Carousels to Take Voters to Polls"
lev$induce[lev$vote_buy==1]="Gave Out Presents to Voters Before the Elections"
lev$induce[lev$threat==1]="Threatened Several Colleagues so They Voted"
lev$induce[is.na(lev$exp_turnout)==TRUE]<-NA

lev$brokertable="  Entrepreneur"
lev$brokertable[lev$doctor==1]=" Head Doctor"
lev$brokertable[lev$worker==1]="Factory Worker"
lev$brokertable[is.na(lev$exp_turnout)==TRUE]<-NA

RussiaPercTable<-table(lev$induce,lev$brokertable)


####### TABLE 3

est1<-felm(elec_honest ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | obl, data=lev )

est2<-felm(elec_meaning ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | obl, data=lev )

est3<-felm(russia_democ ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | obl, data=lev )

est4<-felm(accept_restrict ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | obl, data=lev )

est5<-felm(accept_karusel ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | obl, data=lev )

est6<-felm(accept_media ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | obl, data=lev )



####### TABLE 4


Table4_PanelA<-data.frame(group=numeric(0),
                     strong=numeric(0),
                     weak=numeric(0),
                     opp=numeric(0))
Table4_PanelA[1,]<-c("Control",
                mean(lev$exp_votefor[lev$ur_support>8 & lev$any_fraud==0],na.rm=TRUE),
                mean(lev$exp_votefor[lev$ur_support<=8 & lev$ur_support>4 & lev$any_fraud==0],na.rm=TRUE),
                mean(lev$exp_votefor[lev$ur_support<=4 & lev$any_fraud==0],na.rm=TRUE)
)
Table4_PanelA[2,]<-c("Treatment (Any Fraud)",
                mean(lev$exp_votefor[lev$ur_support>8 & lev$any_fraud==1],na.rm=TRUE),
                mean(lev$exp_votefor[lev$ur_support<=8 & lev$ur_support>4 & lev$any_fraud==1],na.rm=TRUE),
                mean(lev$exp_votefor[lev$ur_support<=4 & lev$any_fraud==1],na.rm=TRUE)
)
Table4_PanelA[,2]<-specify_decimal(as.numeric(Table4_PanelA[,2])*100,1)
Table4_PanelA[,3]<-specify_decimal(as.numeric(Table4_PanelA[,3])*100,1)
Table4_PanelA[,4]<-specify_decimal(as.numeric(Table4_PanelA[,4])*100,1)

names(Table4_PanelA)<-c("","Strong UR Supporters","Weak UR Supporters","Opposition")

Table4_PanelB<-data.frame(group=numeric(0),
                        strong=numeric(0),
                        weak=numeric(0),
                        opp=numeric(0))
Table4_PanelB[1,]<-c("Control",
                   mean(lev$exp_voteagainst[lev$ur_support>8 & lev$any_fraud==0],na.rm=TRUE),
                   mean(lev$exp_voteagainst[lev$ur_support<=8 & lev$ur_support>4 & lev$any_fraud==0],na.rm=TRUE),
                   mean(lev$exp_voteagainst[lev$ur_support<=4 & lev$any_fraud==0],na.rm=TRUE)
)
Table4_PanelB[2,]<-c("Treatment (Any Fraud)",
                   mean(lev$exp_voteagainst[lev$ur_support>8 & lev$any_fraud==1],na.rm=TRUE),
                   mean(lev$exp_voteagainst[lev$ur_support<=8 & lev$ur_support>4 & lev$any_fraud==1],na.rm=TRUE),
                   mean(lev$exp_voteagainst[lev$ur_support<=4 & lev$any_fraud==1],na.rm=TRUE)
)
Table4_PanelB[,2]<-specify_decimal(as.numeric(Table4_PanelB[,2])*100,1)
Table4_PanelB[,3]<-specify_decimal(as.numeric(Table4_PanelB[,3])*100,1)
Table4_PanelB[,4]<-specify_decimal(as.numeric(Table4_PanelB[,4])*100,1)

names(Table4_PanelB)<-c("","Strong UR Supporters","Weak UR Supporters","Opposition")

Table4_PanelC<-data.frame(group=numeric(0),
                       strong=numeric(0),
                       weak=numeric(0),
                       opp=numeric(0))
Table4_PanelC[1,]<-c("Control",
                  mean(lev$exp_votemaybe[lev$ur_support>8 & lev$any_fraud==0],na.rm=TRUE),
                  mean(lev$exp_votemaybe[lev$ur_support<=8 & lev$ur_support>4 & lev$any_fraud==0],na.rm=TRUE),
                  mean(lev$exp_votemaybe[lev$ur_support<=4 & lev$any_fraud==0],na.rm=TRUE)
)
Table4_PanelC[2,]<-c("Treatment (Any Fraud)",
                  mean(lev$exp_votemaybe[lev$ur_support>8 & lev$any_fraud==1],na.rm=TRUE),
                  mean(lev$exp_votemaybe[lev$ur_support<=8 & lev$ur_support>4 & lev$any_fraud==1],na.rm=TRUE),
                  mean(lev$exp_votemaybe[lev$ur_support<=4 & lev$any_fraud==1],na.rm=TRUE)
)
Table4_PanelC[,2]<-specify_decimal(as.numeric(Table4_PanelC[,2])*100,1)
Table4_PanelC[,3]<-specify_decimal(as.numeric(Table4_PanelC[,3])*100,1)
Table4_PanelC[,4]<-specify_decimal(as.numeric(Table4_PanelC[,4])*100,1)

names(Table4_PanelC)<-c("","Strong UR Supporters","Weak UR Supporters","Opposition")


Table4_PanelD<-data.frame(group=numeric(0),
                          strong=numeric(0),
                          weak=numeric(0),
                          opp=numeric(0))
Table4_PanelD[1,]<-c("Control",
                     mean(lev$exp_turnout_dk[lev$ur_support>8 & lev$any_fraud==0],na.rm=TRUE),
                     mean(lev$exp_turnout_dk[lev$ur_support<=8 & lev$ur_support>4 & lev$any_fraud==0],na.rm=TRUE),
                     mean(lev$exp_turnout_dk[lev$ur_support<=4 & lev$any_fraud==0],na.rm=TRUE)
)
Table4_PanelD[2,]<-c("Treatment (Any Fraud)",
                     mean(lev$exp_turnout_dk[lev$ur_support>8 & lev$any_fraud==1],na.rm=TRUE),
                     mean(lev$exp_turnout_dk[lev$ur_support<=8 & lev$ur_support>4 & lev$any_fraud==1],na.rm=TRUE),
                     mean(lev$exp_turnout_dk[lev$ur_support<=4 & lev$any_fraud==1],na.rm=TRUE)
)
Table4_PanelD[,2]<-specify_decimal(as.numeric(Table4_PanelD[,2])*100,1)
Table4_PanelD[,3]<-specify_decimal(as.numeric(Table4_PanelD[,3])*100,1)
Table4_PanelD[,4]<-specify_decimal(as.numeric(Table4_PanelD[,4])*100,1)

names(Table4_PanelD)<-c("","Strong UR Supporters","Weak UR Supporters","Opposition")



############ TABLE 5


est1<-felm(exp_turnout ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | 0, data=subset(lev,control==1) )

est2<-felm(exp_turnout ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | 0, data=lev )

est3<-felm(exp_turnout ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + ur_support | factor(obl) | 0 | 0, data=subset(lev, putin_support==5) )

est4<-felm(exp_turnout ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + ur_support | factor(obl) | 0 | 0, data=subset(lev, putin_support>2 & putin_support<5) )

est5<-felm(exp_turnout ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support | factor(obl) | 0 | 0, data=subset(lev, ur_support>8) )

est6<-felm(exp_turnout ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support | factor(obl) | 0 | 0, data=subset(lev, ur_support<=8 & ur_support>4) )

est7<-felm(exp_turnout ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support | factor(obl) | 0 | 0, data=subset(lev, URvote==1) )

est8<-felm(exp_turnout ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support | factor(obl) | 0 | 0, data=subset(lev, URvote==0) )


##### TABLE 6


est1<-felm(exp_turnout ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + ur_support | factor(obl) | 0 | 0, data=subset(lev, putin_strong==4) )

est2<-felm(exp_turnout ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + ur_support | factor(obl) | 0 | 0, data=subset(lev,putin_strong!=4) )

est3<-felm(exp_turnout ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + ur_support | factor(obl) | 0 | 0, data=subset(lev, putin_honest==4) )

est4<-felm(exp_turnout ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + ur_support | factor(obl) | 0 | 0, data=subset(lev,putin_honest!=4) )

est5<-felm(exp_turnout ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + ur_support | factor(obl) | 0 | 0, data=subset(lev, elec_honest==5) )

est6<-felm(exp_turnout ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + ur_support | factor(obl) | 0 | 0, data=subset(lev,elec_honest!=5) )

est7<-felm(exp_turnout ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + ur_support | factor(obl) | 0 | 0, data=subset(lev, internet2016_politics==1) )

est8<-felm(exp_turnout ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + ur_support | factor(obl) | 0 | 0, data=subset(lev, internet2016_politics==0) )


##### TABLE 7


levmay2018$induce="No Electoral Manipulation"
levmay2018$induce[levmay2018$treat==2 | levmay2018$treat==4]="Organized Carousels to Take Voters to Polls"
levmay2018$induce[is.na(levmay2018$list_outcome)==TRUE]<-NA

levmay2018$outcome="Turnout"
levmay2018$outcome[levmay2018$treat==1 | levmay2018$treat==2]="Vote Choice"
levmay2018$outcome[is.na(levmay2018$list_outcome)==TRUE]<-NA

MayPercTable<-table(levmay2018$induce,levmay2018$outcome)


################################################
############   FIGURES  ########################

###### FIGURE 1

lev$induce_num=" No Manipulation"
lev$induce_num[lev$fraud==1]="Organized Carousel"
lev$induce_num[lev$vote_buy==1]="Bought Votes"
lev$induce_num[lev$threat==1]="Threatened Colleagues"
lev$induce_num[is.na(lev$exp_turnout)==TRUE]<-NA
lev$induce_num<-factor(lev$induce_num)
### Broken Down by Broker
lev$brokertable=NULL
lev$brokertable="Entrepreneur   "
lev$brokertable[lev$doctor==1]="Head Doctor"
lev$brokertable[lev$worker==1]="Factory Worker   "
lev$brokertable[is.na(lev$exp_turnout)==TRUE]<-NA

lev_d<-as.data.table(lev)[,list(average_q123=mean(exp_turnout,na.rm=TRUE)),by=c("induce_num","brokertable")]
lev_d<-subset(lev_d, is.na(induce_num)==FALSE)

ggplot(data=lev_d, aes(x=induce_num, y=average_q123, fill=brokertable)) + geom_bar(colour="black", stat="identity",position=position_dodge(),size=.3)+ scale_fill_grey( name="")+    xlab("") + ylab("Likelihood of Voting for Hypothetical Candidate") + theme_bw()+ theme(legend.position="bottom",axis.text=element_text(size=14),axis.text.x=element_text(face = "bold"),axis.title.y=element_text(size=14),legend.text=element_text(size=12))+ geom_text(aes(label=specify_decimal(average_q123,2)), position=position_dodge(width=0.9), vjust=-0.4) + coord_cartesian(ylim=c(2,3.75))
ggsave(filename = "Figure1.tiff", height=6, width=10)

###### FIGURE 2


lev_broken<-as.data.table(prop.table(table(lev$exp_turnout[lev$control==1])))
lev_broken$treat=0
names(lev_broken)<-c("response","N","treatment")
lev_broken_t<-as.data.table(prop.table(table(lev$exp_turnout[lev$control==0])))
lev_broken_t$treat=1
names(lev_broken_t)<-c("response","N","treatment")
lev_broken<-rbind(lev_broken,lev_broken_t)
lev_broken$treatment<-as.character(lev_broken$treatment)
lev_broken$N<-round(lev_broken$N*100,4)

ggplot(data=lev_broken, aes(x=response, y=N, fill=treatment)) + geom_bar(colour="black", stat="identity",position=position_dodge(),size=.3)+ scale_fill_grey( start = 0.8, end = 0.2,name="",breaks=c("0", "1"),labels=c("Control", "Any Fraud"))+    xlab("Likelihood of Voting for Hypothetical Candidate") + ylab("Percentage of Responses (%)") + theme_bw()+ theme(legend.position="right",axis.text=element_text(size=18),axis.title=element_text(size=18),legend.text=element_text(size=18))+ coord_cartesian(ylim=c(0,40)) + geom_text(aes(label=specify_decimal(N,1)), position=position_dodge(width=0.9), vjust=-0.4,size=5)
ggsave(filename = "Figure2.tiff", height=6, width=10)



###### FIGURE 3

### RES 2000

res2000<-fread("Panel 1999-2000.tab")
res2000$elec_meaning<-Recode(res2000$t51,"7=NA;8=NA;9=NA")
res2000$elec_honest<-Recode(res2000$n87,"5=1;4=2;2=4;1=5;7=NA;8=NA;9=NA")
res2000$duma_honest<-Recode(res2000$t35,"5=1;4=2;2=4;1=5;7=NA;8=NA;9=NA")
res2000$russia_democ<-Recode(res2000$n122,"2=0;7=NA;8=NA;9=NA")

res2000_s<-res2000[,list(elec_meaning=mean(elec_meaning,na.rm=TRUE),
                         elec_honest=mean(elec_honest,na.rm=TRUE),
                         russia_democ=mean(russia_democ,na.rm=TRUE),
                         elec_meaning_sd=sd(elec_meaning,na.rm=TRUE),
                         elec_honest_sd=sd(elec_honest,na.rm=TRUE),
                         russia_democ_sd=sd(russia_democ,na.rm=TRUE)
                         
)]
res2000_s$year=2000

### RES 2004

res2004<-fread("Merge2003_04.tab")
res2004$elec_meaning<-Recode(res2004$w12,"7=NA;8=NA;9=NA")
res2004$elec_honest<-Recode(res2004$w97,"5=1;4=2;2=4;1=5;7=NA;8=NA;9=NA")
res2004$russia_democ<-Recode(res2004$w106,"2=0;7=NA;8=NA;9=NA")

res2004_s<-res2004[,list(elec_meaning=mean(elec_meaning,na.rm=TRUE),
                         elec_honest=mean(elec_honest,na.rm=TRUE),
                         russia_democ=mean(russia_democ,na.rm=TRUE),
                         elec_meaning_sd=sd(elec_meaning,na.rm=TRUE),
                         elec_honest_sd=sd(elec_honest,na.rm=TRUE),
                         russia_democ_sd=sd(russia_democ,na.rm=TRUE))]
res2004_s$year=2004

### RES 2008

res2008<-fread("RES_2008.tab")
res2008$elec_meaning<-Recode(res2008$u22,"7=NA")
res2008$elec_honest<-Recode(res2008$u23,"5=1;4=2;2=4;1=5;7=NA;8=NA;9=NA")
res2008$russia_democ<-Recode(res2008$u28,"2=0;7=NA;8=NA;9=NA")

### Regime support
res2008$choose_hand<-Recode(res2008$u119,"2=1;1=0;8=NA;9=NA;3=NA;7=NA")
res2008$putin_support<-Recode(res2008$u21,"5=1;4=2;2=4;1=5;7=NA;8=NA;9=NA")
res2008$male<-Recode(res2008$u123,"2=0")
res2008$educ<-Recode(res2008$u125,"97=NA;98=NA")
res2008$age<-Recode(res2008$u124a,"98=NA")
res2008$age<-108-res2008$age
res2008$log_age<-log(res2008$age)

res2008_s<-res2008[,list(elec_meaning=mean(elec_meaning,na.rm=TRUE),
                         elec_honest=mean(elec_honest,na.rm=TRUE),
                         russia_democ=mean(russia_democ,na.rm=TRUE),
                         elec_meaning_sd=sd(elec_meaning,na.rm=TRUE),
                         elec_honest_sd=sd(elec_honest,na.rm=TRUE),
                         russia_democ_sd=sd(russia_democ,na.rm=TRUE))]
res2008_s$year=2008

### RES 2012
res2012<-fread("2012 data no labels.tab")
res2012$elec_meaning<-Recode(res2012$v25,"7=NA;8=NA")
res2012$elec_honest<-Recode(res2012$v26,"5=1;4=2;2=4;1=5;7=NA;8=NA;9=NA")
res2012$elec_honest_duma<-Recode(res2012$v27,"5=1;4=2;2=4;1=5;7=NA;8=NA;9=NA")

res2012$russia_democ<-Recode(res2012$v33,"2=0;7=NA;8=NA;9=NA")

res2012$male<-Recode(res2012$v118,"2=0;7=NA;8=NA;9=NA")

res2012$employed<-Recode(res2012$v139,"98=NA")
res2012$employed[res2012$employed>1]<-0

res2012$educ<-Recode(res2012$v120,'97=NA;98=NA;99=NA')

res2012$econ<-Recode(res2012$v127,'97=NA;98=NA;99=NA')

res2012$townsize<-res2012$popquintile

res2012$putin_support<-Recode(res2012$v22,'1=1;2=1;3=0;4=0;5=0;7=NA;8=NA')
res2012$ur_support5<-Recode(res2012$v77,'1=1;2=1;3=0;4=0;5=0;7=NA;8=NA')

res2012$log_age<-log(res2012$age)

res2012$qobl<-res2012$psu

res2012_s<-res2012[,list(elec_meaning=mean(elec_meaning,na.rm=TRUE),
                         elec_honest=mean(elec_honest,na.rm=TRUE),
                         russia_democ=mean(russia_democ,na.rm=TRUE),
                         elec_meaning_sd=sd(elec_meaning,na.rm=TRUE),
                         elec_honest_sd=sd(elec_honest,na.rm=TRUE),
                         russia_democ_sd=sd(russia_democ,na.rm=TRUE))]
res2012_s$year=2012


### RES 2016
res2016_s<-as.data.table(lev)[,list(elec_meaning=mean(elec_meaning,na.rm=TRUE),
                                    elec_honest=mean(elec_honest,na.rm=TRUE),
                                    russia_democ=mean(russia_democ,na.rm=TRUE),
                                    elec_meaning_sd=sd(elec_meaning,na.rm=TRUE),
                                    elec_honest_sd=sd(elec_honest,na.rm=TRUE),
                                    russia_democ_sd=sd(russia_democ,na.rm=TRUE))]
res2016_s$year=2016

res_s<-rbind(res2000_s,res2004_s,res2008_s,res2012_s,res2016_s)
res_s$year<-as.character(res_s$year)
res_s$russia_democ<-res_s$russia_democ*100
res_s$russia_democ_sd<-res_s$russia_democ_sd*100

res_s$elec_meaning_max<-ifelse(res_s$elec_meaning+res_s$elec_meaning_sd>5,5,res_s$elec_meaning+res_s$elec_meaning_sd)
res_s$elec_honest_max<-ifelse(res_s$elec_honest+res_s$elec_honest_sd>5,5,res_s$elec_honest+res_s$elec_honest_sd)


ggplot(res_s,aes(x=year,y=elec_honest,group=1))+
  geom_errorbar(aes(ymin = elec_honest-elec_honest_sd,
                    ymax = elec_honest_max),
                width = 0.05,
                size  = 0.5)+geom_line()+ylim(1,5)+xlab("")+ylab("Was Last Election Conducted Fairly?\n")+theme_bw()+ geom_text(aes(label=specify_decimal(elec_honest,2)),size=6, position=position_dodge(width=0.9), vjust=-0.8,hjust=-0.4)+geom_point()+xlim("2000","2004","2008","2012","2016")+ggtitle("Panel A: Electoral Integrity")+theme(plot.title = element_text(hjust=.5,size=20),axis.text=element_text(size=18),axis.title=element_text(size=20))
ggsave(filename = "Figure3_PanelA.tiff", height=5, width=8)

ggplot(res_s,aes(x=year,y=elec_meaning,group=1))+
  geom_errorbar(aes(ymin = elec_honest-elec_honest_sd,
                    ymax = elec_meaning_max),
                width = 0.05,
                size  = 0.5)+geom_line()+ylim(1,5)+xlab("")+ylab("Do Elections Matter?\n")+theme_bw()+ geom_text(aes(label=specify_decimal(elec_meaning,2)),size=6, position=position_dodge(width=0.9), vjust=-0.8,hjust=-0.4)+geom_point()+xlim("2000","2004","2008","2012","2016")+ggtitle("Panel B: Electoral Impact")+theme(plot.title = element_text(hjust=.5,size=20),axis.text=element_text(size=18),axis.title=element_text(size=20))
ggsave(filename = "Figure3_PanelB.tiff", height=5, width=8)

### APPENDIX Figure 

p3<-ggplot(res_s,aes(x=year,y=russia_democ,group=1))+geom_line()+ylim(0,100)+xlab("\nSurvey Year")+ylab("Is Russia a Democracy?")+theme_bw()+ geom_text(aes(label=paste(specify_decimal(russia_democ,1),"%",sep="")),size=6, position=position_dodge(width=0.9), vjust=1.1,hjust=-0.3)+geom_point()+xlim("2000","2004","2008","2012","2016")+theme(plot.title = element_text(hjust=.5,size=20),axis.text=element_text(size=18),axis.title=element_text(size=20))






####### FIGURE 3

lev_t<-subset(lev, is.na(exp_turnout)==FALSE 
              & is.na(any_fraud)==FALSE 
              & is.na(putin_support)==FALSE 
              & is.na(male)==FALSE
              & is.na(log_age)==FALSE
              & is.na(educ)==FALSE
              & is.na(townsize)==FALSE
              & is.na(econ)==FALSE
              & is.na(employed)==FALSE
              & is.na(voted)==FALSE
              & is.na(number_org)==FALSE
              & is.na(follow_pol)==FALSE
              & is.na(obl)==FALSE
              & is.na(ur_support)==FALSE 
              
)
est1<-lm(exp_turnout ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + factor(obl), data=lev_t)
lev_t$residuals<-est1$residuals

est1<-lm(residuals ~ any_fraud*ur_support, data=lev_t)
est2<-felm(residuals ~ any_fraud*ur_support |0|0|obl, data=lev_t)

p2 <- interplot(m = est1, var1 = "any_fraud", var2 = "ur_support", hist = TRUE) +
  geom_hline(yintercept = 0, linetype = "dashed")+
  aes(color = "pink")+ theme(legend.position="none")+
  scale_x_continuous(breaks = c(0,1,2,3,4,5,6,7,8,9,10))+xlab("UR Approval Rating\n\n\n")+ylab("Marginal Effect of Any Fraud Treatment")+ggtitle("Panel B: UR Approval")+theme(plot.title = element_text(hjust = 0.5,size=16),axis.title = element_text(size=14),axis.text = element_text(size=14))

est3<-lm(residuals ~ any_fraud*putin_support, data=lev_t)

p1 <- interplot(m = est3, var1 = "any_fraud", var2 = "putin_support", hist = TRUE) +
  geom_hline(yintercept = 0, linetype = "dashed")+
  aes(color = "pink")+ theme(legend.position="none")+
  scale_x_continuous(breaks = c(1,2,3,4,5))+xlab("Putin Approval Rating\n\n\n")+ylab("Marginal Effect of Any Fraud Treatment")+ggtitle("Panel A: Putin Approval")+theme(plot.title = element_text(hjust = 0.5,size=16),axis.title = element_text(size=14),axis.text = element_text(size=14))

####### FIGURE 4


lev_t<-subset(lev, is.na(exp_turnout)==FALSE 
              & is.na(any_fraud)==FALSE 
              & is.na(putin_support)==FALSE 
              & is.na(male)==FALSE
              & is.na(log_age)==FALSE
              & is.na(educ)==FALSE
              & is.na(townsize)==FALSE
              & is.na(econ)==FALSE
              & is.na(employed)==FALSE
              & is.na(voted)==FALSE
              & is.na(number_org)==FALSE
              & is.na(follow_pol)==FALSE
              & is.na(obl)==FALSE
              & is.na(ur_support)==FALSE 
              
)
est1<-lm(exp_turnout ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + factor(obl), data=lev_t)
lev_t$residuals<-est1$residuals

est1<-lm(residuals ~ any_fraud*ur_support, data=lev_t)

p2 <- interplot(m = est1, var1 = "any_fraud", var2 = "ur_support", hist = TRUE) +
  geom_hline(yintercept = 0, linetype = "dashed")+
  aes(color = "pink")+ theme(legend.position="none")+
  scale_x_continuous(breaks = c(0,1,2,3,4,5,6,7,8,9,10))+xlab("UR Approval Rating\n\n\n")+ylab("Marginal Effect of Any Fraud Treatment")+ggtitle("Panel B: UR Approval")+theme(plot.title = element_text(hjust = 0.5,size=16),axis.title = element_text(size=14),axis.text = element_text(size=14))

est3<-lm(residuals ~ any_fraud*putin_support, data=lev_t)

p1 <- interplot(m = est3, var1 = "any_fraud", var2 = "putin_support", hist = TRUE) +
  geom_hline(yintercept = 0, linetype = "dashed")+
  aes(color = "pink")+ theme(legend.position="none")+
  scale_x_continuous(breaks = c(1,2,3,4,5))+xlab("Putin Approval Rating\n\n\n")+ylab("Marginal Effect of Any Fraud Treatment")+ggtitle("Panel A: Putin Approval")+theme(plot.title = element_text(hjust = 0.5,size=16),axis.title = element_text(size=14),axis.text = element_text(size=14))



####### FIGURE 5


levmay2018_exp2<-subset(levmay2018, treat>=3)

levmay2018_exp2$induce_num=NULL
levmay2018_exp2$induce_num[levmay2018_exp2$treat==3]=" No Manipulation"
levmay2018_exp2$induce_num[levmay2018_exp2$treat==4]="Organized Carousel"

lev_d<-as.data.table(levmay2018_exp2)[,list(list_outcome=mean(list_outcome,na.rm=TRUE)),by=c("induce_num")]
lev_d<-subset(lev_d, is.na(induce_num)==FALSE)

ggplot(data=lev_d, aes(x=induce_num, y=list_outcome, fill=induce_num)) + geom_bar(colour="black", stat="identity",position=position_dodge(),size=.3)+ scale_fill_grey( name="")+    xlab("") + ylab("\nLikelihood of Voting\n") + theme_bw()+ theme(legend.position="none",axis.text=element_text(size=14),axis.title.y=element_text(size=14),legend.text=element_text(size=12),plot.title=element_text(size=18,hjust=0.5))+ geom_text(aes(label=specify_decimal(list_outcome,2)), position=position_dodge(width=0.9), vjust=-0.4) + coord_cartesian(ylim=c(2,3.75))+ggtitle("2018 Turnout Experiment")
ggsave(filename = "Figure5_PanelA.tiff", height=5, width=6)


levmay2018_exp1<-subset(levmay2018, treat<=2)

levmay2018_exp1$induce_num=NULL
levmay2018_exp1$induce_num[levmay2018_exp1$treat==1]=" No Manipulation"
levmay2018_exp1$induce_num[levmay2018_exp1$treat==2]="Organized Carousel"

lev_d<-as.data.table(levmay2018_exp1)[,list(list_outcome=mean(list_outcome,na.rm=TRUE)),by=c("induce_num")]
lev_d<-subset(lev_d, is.na(induce_num)==FALSE)

ggplot(data=lev_d, aes(x=induce_num, y=list_outcome, fill=induce_num)) + geom_bar(colour="black", stat="identity",position=position_dodge(),size=.3)+ scale_fill_grey( name="")+    xlab("") + ylab("Likelihood of Voting for Hypothetical Candidate\n") + theme_bw()+ theme(legend.position="none",axis.text=element_text(size=14),axis.title.y=element_text(size=14),legend.text=element_text(size=12),plot.title=element_text(size=18,hjust=0.5))+ geom_text(aes(label=specify_decimal(list_outcome,2)), position=position_dodge(width=0.9), vjust=-0.4) + coord_cartesian(ylim=c(2,3.75))+ggtitle("2018 Vote Choice Experiment")
ggsave(filename = "Figure5_PanelB.tiff", height=5, width=6)






##################################
#######  APPENDIX     ###########
##################################


##### TABLE A1

lev<-as.data.table(lev)
lev_summary<-as.data.table(lev)[,list(male,log_age,educ,townsize,econ,employed,kpss,number_org,follow_pol,putin_support,ur_support,putin_honest,putin_strong,elec_honest,russia_democ,elec_meaning,accept_restrict,accept_karusel,accept_media,voted,URvote)]

electionstable<-mod_stargazer(stargazer(lev_summary,covariate.labels=c(
  "Male",
  "Age (log)",
  "Education",
  "Town Size",
  "Economic Situation",
  "Employed",
  "CPSU Member",
  "Number of Civil Society Organizations",
  "Follows Politics",
  "Support for Putin",
  "Support for United Russia",
  "Is Putin Honest?",
  "Is Putin Strong?",
  
  "Electoral Integrity",
  "Is Russia a Democracy?",
  "Electoral Impact",
  "Acceptability of Blocking Opposition",
  "Acceptability of Organizing Carousel Voting",
  "Acceptability of Media Restributions",
  "Voted in Duma Election",
  "Voted in Duma Election for United Russia"),header=FALSE,digits=3))

electionstable <-gsub("\\begin{table}[!htbp]", "", electionstable, fixed =TRUE)
electionstable <-gsub("\\end{table}", "", electionstable, fixed =TRUE)
electionstable <-gsub("\\caption{}", "", electionstable, fixed =TRUE)
electionstable <-gsub("0.00000", "0", electionstable, fixed =TRUE)


#### TABLE A3


mm <- multinom(variant_q123 ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol+ putin_support + ur_support + elec_honest + russia_democ, data=lev, trace=F)
ind_chi<-Anova(mm)

cdfs_mlog<-mlogit.data(lev, choice="variant_q123",shape="wide")
t_mlog<-mlogit(variant_q123 ~ 0 | male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol+ putin_support + ur_support + elec_honest + russia_democ, data = cdfs_mlog)
names(summary(t_mlog)[17])

chi<-specify_decimal(do.call(rbind, summary(t_mlog)[17])[[1]][1],2)

p<-specify_decimal(do.call(rbind, summary(t_mlog)[17])[[3]][1],4)

mm <- multinom(any_fraud ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol+ putin_support + ur_support + elec_honest + russia_democ, data=lev, trace=F)
ind_chi2<-Anova(mm)

cdfs_mlog<-mlogit.data(lev, choice="any_fraud",shape="wide")
t_mlog<-mlogit(any_fraud ~ 0 | male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol+ putin_support + ur_support + elec_honest + russia_democ, data = cdfs_mlog)

chi2<-specify_decimal(do.call(rbind, summary(t_mlog)[17])[[1]][1],2)

p2<-specify_decimal(do.call(rbind, summary(t_mlog)[17])[[3]][1],4)

ind<-cbind(ind_chi,ind_chi2)

rownames( ind ) <- c("Male","Age (log)","Education","Town Size","Economic Situation","Employed","CPSU Member","Voted","No. Civil Society Orgs","Interest in Politics","Putin Support","UR Support","Perception of Electoral Integrity","Is Russia a Democracy?" )


### FIGURE A1


lev_broken<-as.data.table(prop.table(table(lev$exp_turnout[lev$control==1])))
lev_broken$treat=0
names(lev_broken)<-c("response","N","treatment")
lev_broken_t<-as.data.table(prop.table(table(lev$exp_turnout[lev$control==0])))
lev_broken_t$treat=1
names(lev_broken_t)<-c("response","N","treatment")
lev_broken<-rbind(lev_broken,lev_broken_t)
lev_broken$treatment<-as.character(lev_broken$treatment)
lev_broken$N<-round(lev_broken$N*100,4)

ggplot(data=lev_broken, aes(x=response, y=N, fill=treatment)) + geom_bar(colour="black", stat="identity",position=position_dodge(),size=.3)+ scale_fill_grey( start = 0.8, end = 0.2,name="",breaks=c("0", "1"),labels=c("Control", "Any Fraud"))+    xlab("Likelihood of Voting for Hypothetical Candidate") + ylab("Percentage of Responses (%)") + theme_bw()+ theme(legend.position="right",axis.text=element_text(size=18),axis.title=element_text(size=18),legend.text=element_text(size=18))+ coord_cartesian(ylim=c(0,40)) + geom_text(aes(label=specify_decimal(N,1)), position=position_dodge(width=0.9), vjust=-0.4,size=5)







#######  TABLE B2

lev2011<-read.dta("lev2011.dta")

lev2011$log_age<-log(lev2011$age)
lev2011$educ<-as.numeric(lev2011$ordeduc)
lev2011$townsize<-car::Recode(as.numeric(lev2011$townsize),"1=7;2=6;3=5;5=3;6=2;7=1;97=NA;98=NA")
lev2011$votes<-as.numeric(lev2011$q29)-1

lev2011$putin_support1<-as.numeric(lev2011$q4b)*-1+2
lev2011$ur_support1<-lev2011$ursupporter

lev2011$elec_honest<-car::Recode(as.numeric(lev2011$q47),"1=4;2=3;3=2;4=1;5=NA;8=NA")
lev2011$econ<-as.numeric(lev2011$constatus)

lev2011$elec_violations<-car::Recode(as.numeric(lev2011$q49),"5=NA")
lev2011$elec_badviolations<-car::Recode(as.numeric(lev2011$q49),"5=NA;1=0;2=0;3=0;4=1")

lev2011$elec_accuracy<-car::Recode(as.numeric(lev2011$q50),"5=NA")


lev2011<-as.data.table(lev2011)

ViolationsTable<-lev2011[,.(total=.N,
                            freq=round(.N/length(lev2011$elec_violations[is.na(lev2011$elec_violations)==FALSE]),2),
                            totalur=length(elec_violations[putin_support1==1]),
                            frequr=round(length(elec_violations[putin_support1==1])/length(lev2011$elec_violations[is.na(lev2011$elec_violations)==FALSE & lev2011$putin_support1==1]),2),
                            totalopp=length(elec_violations[putin_support1==0]),
                            freqpp=round(length(elec_violations[putin_support1==0])/length(lev2011$elec_violations[is.na(lev2011$elec_violations)==FALSE & lev2011$putin_support1==0]),2) ),
                         by=c("elec_violations")]
ViolationsTable<-subset(ViolationsTable, is.na(elec_violations)==FALSE)  
ViolationsTable<-ViolationsTable[order(elec_violations)]

ViolationsTable$elec_violations<-c("1. There weren't any violations.","2. There were insignificant violations.","3. There were quite significant violations, but they were unlikely to change the electoral results.","4. There were significant violations that changed the electoral results.")

names(ViolationsTable)<-c("Response","All Resp.","(%)","Putin Supporters","(%)","Opposition Supporters","(%)")


#######  TABLE B3


lev2016<-as.data.table(read.dta13("lev2016.dta"))

lev2016[,elec_violations:=car::Recode(as.numeric(q49),"9=NA")]
lev2016[,elec_badviolations:=car::Recode(as.numeric(q49),"5=NA;1=0;2=0;3=0;4=1;9=NA")]

lev2016[,putin_support:=ifelse(q3A==1,1,0)]

lev2016[,male:=as.numeric(qS1)*-1+2]

lev2016[,log_age:=log(qS2)]
lev2016[,educ:=as.numeric(qS3)]
lev2016[,townsize:=car::Recode(as.numeric(qRNP),"1=5;2=4;4=2;5=1;97=NA;98=NA")]
lev2016[,votes:=car::Recode(as.numeric(q29),"2=1;1=0;8=NA;9=NA")]
lev2016[,elec_honest:=car::Recode(as.numeric(q47),"1=4;2=3;3=2;4=1;5=NA;8=NA;9=NA")]

lev2016[,econ:=as.numeric(qD8)]
lev2016[,employed:=ifelse(qD4<=5,1,0)]

lev2016[,ur_support:=car::Recode(as.numeric(q33),"97=NA;98=NA;99=NA")]
lev2016[,ur_support:=ifelse(ur_support==4,1,0)]

Violations2016Table<-lev2016[,.(total=.N,
                                freq=round(.N/length(lev2016$elec_violations[is.na(lev2016$elec_violations)==FALSE]),2),
                                totalur=length(elec_violations[putin_support==1]),
                                frequr=round(length(elec_violations[putin_support==1])/length(lev2016$elec_violations[is.na(lev2016$elec_violations)==FALSE & lev2016$putin_support==1]),2),
                                totalopp=length(elec_violations[putin_support==0]),
                                freqpp=round(length(elec_violations[putin_support==0])/length(lev2016$elec_violations[is.na(lev2016$elec_violations)==FALSE & lev2016$putin_support==0]),2) ),
                             by=c("elec_violations")]
Violations2016Table<-subset(Violations2016Table, is.na(elec_violations)==FALSE)  
Violations2016Table<-Violations2016Table[order(elec_violations)]

Violations2016Table$elec_violations<-c("1. There weren't any violations.","2. There were insignificant violations.","3. There were quite significant violations, but they were unlikely to change the electoral results.","4. There were significant violations that changed the electoral results.")

names(Violations2016Table)<-c("Response","All Resp.","(%)","Putin Supporters","(%)","Opposition Supporters","(%)")


##### TABLE B4


gr<-as.data.table(read.dta13("ElectionMonitors2012.dta"))

gr$opp_voter[gr$non_voter==1]<-NA
gr$regime_voter[gr$non_voter==1]<-NA

prop.table(table(gr$golos_correct,gr$opp_voter))



ViolationsTable<-gr[is.na(gr$golos_correct)==FALSE][,.(total=.N,
                                                       freq=round(.N/length(gr$golos_correct),2),
                                                       regime=length(golos_correct[regime_voter==1 & is.na(regime_voter)==FALSE]),
                                                       regime_freq=round(length(golos_correct[regime_voter==1 & is.na(regime_voter)==FALSE])/length(gr$golos_correct[gr$regime_voter==1 & is.na(gr$regime_voter)==FALSE]),2),
                                                       opp=length(golos_correct[opp_voter==1 & is.na(opp_voter)==FALSE]),
                                                       opp_freq=round(length(golos_correct[opp_voter==1 & is.na(opp_voter)==FALSE])/length(gr$golos_correct[gr$opp_voter==1 & is.na(gr$opp_voter)==FALSE]),2),
                                                       non=length(golos_correct[non_voter==1 & is.na(non_voter)==FALSE]),
                                                       non_freq=round(length(golos_correct[non_voter==1 & is.na(non_voter)==FALSE])/length(gr$golos_correct[gr$non_voter==1 & is.na(gr$non_voter)==FALSE]),2)
                                                       
                                                       
                                                       
),

by=c("golos_correct")]
ViolationsTable


ViolationsTable$golos_correct<-c("0. No","1. Yes")

names(ViolationsTable)<-c("Response","All Resp.","(%)","UR Voters","(%)","Opposition Voters","(%)","Non-Voters","(%)")


#### TABLE B5

est2011 <- felm(elec_honest ~ male + log_age + educ + townsize + econ + employed + putin_support1 + ur_support1 | factor(qobl) | 0 | qobl, data=lev2011)

est2012 <- felm(elec_honest ~ male + log_age + educ + townsize + econ + employed + putin_support + ur_support5 | factor(qobl) | 0 | qobl, data=res2012)

est2012_duma <- felm(elec_honest_duma ~ male + log_age + educ + townsize + econ + employed + putin_support + ur_support5 | factor(qobl) | 0 | qobl, data=res2012)

est2016<-felm(elec_honest ~ male + log_age + educ + townsize + econ + employed + putin_support + ur_support| factor(obl) | 0 | obl, data=lev )


#### TABLE B6


est1<-felm(russia_democ ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | obl, data=lev )

est2<-felm(real_choice ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | obl, data=lev )

est3<-felm(free_media ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | obl, data=lev )

est4<-felm(filtering ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | obl, data=lev )


#### TABLE B7


est1<-felm(elec_honest~ male + log_age + educ + townsize + econ + employed + putin_support1 + ur_support1 + elec_violations | factor(qobl) | 0 | qobl, data=lev2011)

est2<-felm(elec_honest~ male + log_age + educ + townsize + econ + employed + putin_support1 + ur_support1 + elec_violations*putin_support1| factor(qobl) | 0 | qobl, data=lev2011)

est3<-felm(elec_honest~ male + log_age + educ + townsize + econ + employed + putin_support1 + ur_support1 + elec_badviolations | factor(qobl) | 0 | qobl, data=lev2011)

est4<-felm(elec_honest~male + log_age + educ + townsize + econ + employed + putin_support1 + ur_support1 + elec_badviolations*putin_support1 | factor(qobl) | 0 | qobl, data=lev2011)


#### TABLE B8


est1<-felm(elec_honest~ male + log_age + educ + townsize + econ + employed + putin_support + elec_violations | factor(qOBL) | 0 | qOBL, data=lev2016)

est2<-felm(elec_honest~ male + log_age + educ + townsize + econ + employed + putin_support  + elec_violations*putin_support| factor(qOBL) | 0 | qOBL, data=lev2016)

est3<-felm(elec_honest~ male + log_age + educ + townsize + econ + employed + putin_support+ elec_badviolations | factor(qOBL) | 0 | qOBL, data=lev2016)

est4<-felm(elec_honest~male + log_age + educ + townsize + econ + employed + putin_support + elec_badviolations*putin_support | factor(qOBL) | 0 | qOBL, data=lev2016)


#### TABLE B9



est1<-felm(exp_turnout ~ any_fraud+internet2016_politics+any_fraud:internet2016_politics + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol  | factor(obl) | 0 | obl, data=subset(lev, ur_support>5))

est2<-felm(exp_turnout ~ any_fraud+internet_frequency+any_fraud:internet_frequency + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol  | factor(obl) | 0 | obl, data=subset(lev, ur_support>5))

est3<-felm(exp_turnout ~ any_fraud+fb_twitter+any_fraud:fb_twitter + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol  | factor(obl) | 0 | obl, data=subset(lev, ur_support>5))

est4<-felm(exp_turnout ~ any_fraud+internet_socialmedia+any_fraud:internet_socialmedia + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol  | factor(obl) | 0 | obl, data=subset(lev, ur_support>5))

est5<-felm(exp_turnout ~ any_fraud+frequent_state_news+any_fraud:frequent_state_news + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol  | factor(obl) | 0 | obl, data=subset(lev, ur_support>5))

est6<-felm(exp_turnout ~ any_fraud+elec_honest+any_fraud:elec_honest + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol  | factor(obl) | 0 | obl, data=subset(lev, ur_support>5))




#### TABLE C1


est1<-felm(exp_turnout ~ any_fraud+putin_support_demean+any_fraud:putin_support_demean + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol | factor(obl) | 0 | 0, data=lev)

est2<-felm(exp_turnout ~ any_fraud+ur_support_demean+any_fraud:ur_support_demean + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol | factor(obl) | 0 | 0, data=lev)

est3<-felm(exp_turnout ~ any_fraud+URvote+any_fraud:URvote + male + log_age + educ + townsize + econ + employed + kpss + number_org + follow_pol | factor(obl) | 0 | 0, data=lev)

est4<-felm(exp_turnout ~ any_fraud+putin_honest_demean+any_fraud:putin_honest_demean + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol | factor(obl) | 0 | 0, data=lev)

est5<-felm(exp_turnout ~ any_fraud+putin_strong_demean+any_fraud:putin_strong_demean + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol | factor(obl) | 0 | 0, data=lev)

est6<-felm(exp_turnout ~ any_fraud+elec_honest_demean+any_fraud:elec_honest_demean + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol | factor(obl) | 0 | 0, data=lev)

est7<-felm(exp_turnout ~ any_fraud+internet2016_politics+any_fraud:internet2016_politics + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol | factor(obl) | 0 | 0, data=lev)



##### TABLE C2


est1<-felm(voted ~ male + log_age + educ + townsize + econ + employed + kpss + number_org + follow_pol +elec_honest | factor(obl) | 0 | obl, data=subset(lev,ur_support>8 ))

est2<-felm(voted ~ male + log_age + educ + townsize + econ + employed + kpss + number_org + follow_pol +elec_honest | factor(obl) | 0 | obl, data=subset(lev,ur_support<=8 )   )        

est3<-felm(voted ~ male + log_age + educ + townsize + econ + employed + kpss + number_org + follow_pol +elec_meaning | factor(obl) | 0 | obl, data=subset(lev,ur_support>8 ))

est4<-felm(voted ~ male + log_age + educ + townsize + econ + employed + kpss + number_org + follow_pol + elec_meaning | factor(obl) | 0 | obl, data=subset(lev,ur_support<=8 )   )     

est5<-felm(voted ~ male + log_age + educ + townsize + econ + employed + kpss + number_org + follow_pol +russia_democ | factor(obl) | 0 | obl, data=subset(lev,ur_support>8 ))

est6<-felm(voted ~ male + log_age + educ + townsize + econ + employed + kpss + number_org + follow_pol +russia_democ | factor(obl) | 0 | obl, data=subset(lev,ur_support<=8 )   )     


#### FIGURE C1

lev$induce_num=NULL
lev$induce_num=" No Manipulation"
lev$induce_num[lev$fraud==1]="Organized Carousel"
lev$induce_num[lev$vote_buy==1]="Bought Votes"
lev$induce_num[lev$threat==1]="Threatened Colleagues"
lev$induce_num[is.na(lev$exp_turnout_dk)==TRUE]<-NA
lev$induce_num<-factor(lev$induce_num)

lev_d<-as.data.table(lev)[,list(average_q123_dk=mean(exp_turnout_dk,na.rm=TRUE)),by=c("induce_num")]
lev_d<-subset(lev_d, is.na(induce_num)==FALSE)


ggplot(data=lev_d, aes(x=induce_num, y=average_q123_dk)) + geom_bar(colour="black", stat="identity",position=position_dodge(),size=.3)+ scale_fill_grey( name="")+    xlab("") + ylab("Likelihood of Answering Don't Know") + theme_bw()+ theme(legend.position="bottom",axis.text=element_text(size=14),axis.text.x=element_text(face = "bold"),axis.title.y=element_text(size=14),legend.text=element_text(size=12))+ geom_text(aes(label=specify_decimal(average_q123_dk,2)), position=position_dodge(width=0.9), vjust=-0.4) + coord_cartesian(ylim=c(0,.5))


#### TABLE C3



est1<-felm(exp_turnout_dk ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | 0, data=subset(lev,control==1) )

est2<-felm(exp_turnout_dk ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | 0, data=lev )

est3<-felm(exp_turnout_dk ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + ur_support | factor(obl) | 0 | 0, data=subset(lev, putin_support==5) )

est4<-felm(exp_turnout_dk ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + ur_support | factor(obl) | 0 | 0, data=subset(lev, putin_support>2 & putin_support<5) )

est5<-felm(exp_turnout_dk ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support | factor(obl) | 0 | 0, data=subset(lev, ur_support>8) )

est6<-felm(exp_turnout_dk ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support | factor(obl) | 0 | 0, data=subset(lev, ur_support<=8 & ur_support>4) )

est7<-felm(exp_turnout_dk ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support | factor(obl) | 0 | 0, data=subset(lev, URvote==1) )

est8<-felm(exp_turnout_dk ~ any_fraud + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support | factor(obl) | 0 | 0, data=subset(lev, URvote==0) )



#### TABLE C4


est1<-felm(accept_attend ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | obl, data=lev )

est2<-felm(accept_media ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | obl, data=lev )

est3<-felm(accept_restrict ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | obl, data=lev )

est4<-felm(accept_pensioner ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | obl, data=lev )

est5<-felm(accept_buy_rally ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | obl, data=lev )

est6<-felm(accept_wpthreat ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | obl, data=lev )

est7<-felm(accept_karusel ~ male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | obl, data=lev )


#### TABLE C5

est1<-felm(exp_turnout ~ any_fraud*log_age + male + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | 0, data=lev )

est2<-felm(exp_turnout ~ full_fraud+full_fraud:log_age + log_age + male + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | 0, data=lev )

est3<-felm(exp_turnout ~ any_fraud*educ + male + log_age + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | 0, data=lev )

est4<-felm(exp_turnout ~ full_fraud + full_fraud:educ + educ + male + log_age + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | 0, data=lev )

est5<-felm(exp_turnout ~ any_fraud*employed + male + log_age + townsize + econ + educ + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | 0, data=lev )

est6<-felm(exp_turnout ~ full_fraud + full_fraud:employed + employed + male + log_age + townsize + econ + educ + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | 0, data=lev )

est7<-felm(exp_turnout ~ any_fraud+ any_fraud:ur_support+ log_age + male + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | 0, data=lev )

est8<-felm(exp_turnout ~ full_fraud+full_fraud:ur_support + log_age + male + log_age + educ + townsize + econ + employed + kpss + voted + number_org + follow_pol + putin_support + ur_support| factor(obl) | 0 | 0, data=lev )




#### TABLE E1


levmay2018<-as.data.table(levmay2018)
lev_summary2018<-as.data.table(levmay2018)[,list(male,log_age,educ,townsize,econ,employed,follow_pol,putinapproval,ur_support,voted)]

lev2018table<-mod_stargazer(stargazer(lev_summary2018,covariate.labels=c(
  "Male",
  "Age (log)",
  "Education",
  "Town Size",
  "Economic Situation",
  "Employed",
  "Follows Politics",
  "Support for Putin",
  "Support for United Russia",
  "Voted in 2018 Presidential Election"),header=FALSE,digits=3))


##### TABLE E3

levmay2018_exp1_t<-subset(levmay2018_exp1, is.na(list_outcome)==FALSE 
                          & is.na(treat)==FALSE 
                          & is.na(putinapproval)==FALSE 
                          & is.na(ur_support)==FALSE 
                          
                          & is.na(male)==FALSE
                          & is.na(log_age)==FALSE
                          & is.na(educ)==FALSE
                          & is.na(townsize)==FALSE
                          & is.na(econ)==FALSE
                          & is.na(employed)==FALSE
                          & is.na(voted)==FALSE
                          & is.na(follow_pol)==FALSE
                          & is.na(obl)==FALSE
                          
)


levmay2018_exp2_t<-subset(levmay2018_exp2, is.na(list_outcome)==FALSE 
                          & is.na(treat)==FALSE 
                          & is.na(putinapproval)==FALSE 
                          & is.na(ur_support)==FALSE 
                          
                          & is.na(male)==FALSE
                          & is.na(log_age)==FALSE
                          & is.na(educ)==FALSE
                          & is.na(townsize)==FALSE
                          & is.na(econ)==FALSE
                          & is.na(employed)==FALSE
                          & is.na(voted)==FALSE
                          & is.na(follow_pol)==FALSE
                          & is.na(obl)==FALSE
)


mm <- multinom(treat ~ male + log_age + educ + townsize + econ + employed + voted, data=levmay2018_exp1_t, trace=F)
ind_chi<-Anova(mm)

cdfs_mlog<-mlogit.data(levmay2018_exp1_t, choice="treat",shape="wide")
t_mlog<-mlogit(treat ~ 0 | male + log_age + educ + townsize + econ + employed + voted, data = cdfs_mlog)

chi<-specify_decimal(do.call(rbind, summary(t_mlog)[17])[[1]][1],2)

p<-specify_decimal(do.call(rbind, summary(t_mlog)[17])[[3]][1],4)

mm <- multinom(treat ~ male + log_age + educ + townsize + econ + employed + voted, data=levmay2018_exp2_t, trace=F)
ind_chi2<-Anova(mm)

cdfs_mlog<-mlogit.data(levmay2018_exp2_t, choice="treat",shape="wide")
t_mlog<-mlogit(treat ~ 0 | male + log_age + educ + townsize + econ + employed + voted, data = cdfs_mlog)

chi2<-specify_decimal(do.call(rbind, summary(t_mlog)[17])[[1]][1],2)

p2<-specify_decimal(do.call(rbind, summary(t_mlog)[17])[[3]][1],4)

ind<-cbind(ind_chi,ind_chi2)

rownames( ind ) <- c("Male","Age (log)","Education","Town Size","Economic Situation","Employed","Voted")



### FIGURE 3

est1<-lm(list_outcome ~ male + log_age + educ + townsize + econ + employed + voted + follow_pol, data=levmay2018_exp2_t)
levmay2018_exp2_t$residuals<-est1$residuals

est1<-lm(residuals ~ treat*ur_support, data=levmay2018_exp2_t)

p2 <- interplot(m = est1, var1 = "treat", var2 = "ur_support", hist = TRUE) +
  geom_hline(yintercept = 0, linetype = "dashed")+
  aes(color = "pink")+ theme(legend.position="none",plot.title=element_text(size=18,hjust=0.5),axis.text=element_text(size=14),axis.title=element_text(size=14))+
  scale_x_continuous(breaks = c(1,2,3,4,5,6,7,8,9,10))+xlab("UR Approval Rating\n\n\n")+ylab("Marginal Effect of Fraud Treatment")+ggtitle("2018 Turnout Experiment")
p2

est1<-lm(list_outcome ~ male + log_age + educ + townsize + econ + employed + voted + follow_pol, data=levmay2018_exp1_t)
levmay2018_exp1_t$residuals<-est1$residuals
est1<-lm(residuals ~ treat*ur_support, data=levmay2018_exp1_t)

p1 <- interplot(m = est1, var1 = "treat", var2 = "ur_support", hist = TRUE) +
  geom_hline(yintercept = 0, linetype = "dashed")+
  aes(color = "pink")+ theme(legend.position="none",plot.title=element_text(size=18,hjust=0.5),axis.text=element_text(size=14),axis.title=element_text(size=14))+
  scale_x_continuous(breaks = c(1,2,3,4,5,6,7,8,9,10))+xlab("UR Approval Rating\n\n\n")+ylab("Marginal Effect of Fraud Treatment")+ggtitle("2018 Vote Choice Experiment")
p1



##### TABLE F1

#### LOAD the World Values Survey Aggregated (1981-2014) WVS data-file: WVS_Longitudinal_1981_2014_stata_v2015_04_18.dta as wvs. This is available on the data section of the WVS website.

wvs$S003<-as.character(wvs$S003)
wvs<-subset(wvs, S002=="2010-2014")
wvs<-subset(wvs, E265_01!="Not asked in survey")

### kuwait, libya, 
wvs<-subset(wvs, S003=="Nigeria" | 
              S003=="Russia" | 
              S003=="Morocco" | 
              S003=="Armenia" | 
              S003=="Malaysia" | 
              S003=="Azerbaijan" | 
              S003=="Belarus" | 
              S003=="Ukraine" | 
              S003=="Uzbekistan" | 
              S003=="Zimbabwe" | 
              S003=="Kazakhstan" | 
              S003=="Rwanda" | 
              S003=="Singapore" | 
              S003=="Egypt" | 
              S003=="Yemen" | 
              S003=="Algeria" | 
              S003=="Jordan" | 
              S003=="Argentina" | 
              S003=="Netherlands" | 
              S003=="Poland" | 
              S003=="Germany" | 
              S003 =="Taiwan")

wvs$democ<-ifelse(wvs$S003=="Argentina" | 
                    wvs$S003=="Netherlands" | 
                    wvs$S003=="Poland" | 
                    wvs$S003=="Germany" | 
                    wvs$S003 =="Taiwan",1,0)

wvs$E265_01<-as.character(wvs$E265_01)
wvs$E265_02<-as.character(wvs$E265_02)
wvs$E265_03<-as.character(wvs$E265_03)
wvs$E265_04<-as.character(wvs$E265_04)
wvs$E265_05<-as.character(wvs$E265_05)
wvs$E265_06<-as.character(wvs$E265_06)
wvs$E265_07<-as.character(wvs$E265_07)
wvs$E265_08<-as.character(wvs$E265_08)
wvs$E265_09<-as.character(wvs$E265_09)
wvs$E236<-as.character(wvs$E236)

wvs$S025<-as.character(wvs$S025)
wvs[wvs=="Missing; Unknown" | wvs=="No answer" | wvs=="Don´t know"]<-NA
wvs[wvs=="Not at all democratic"]<-1
wvs[wvs=="Completely democratic"]<-10

wvs<-as.data.table(wvs)
wvs$E236<-as.numeric(wvs$E236)

wvs_summary<-wvs

wvs_summary[wvs_summary=="Not at all often" | wvs_summary=="Not often" ]<-0
wvs_summary[wvs_summary=="Fairly often" | wvs_summary=="Very often"]<-1

wvs_summary$E265_01<-ifelse(wvs_summary$E265_01==1,0,1)
wvs_summary$E265_05<-ifelse(wvs_summary$E265_05==1,0,1)
wvs_summary$E265_09<-ifelse(wvs_summary$E265_09==1,0,1)

countries<-wvs_summary[,list(E236=mean(as.numeric(E236),na.rm=TRUE),
                             E265_01=mean(as.numeric(E265_01),na.rm=TRUE),
                             E265_02=mean(as.numeric(E265_02),na.rm=TRUE),
                             E265_04=mean(as.numeric(E265_04),na.rm=TRUE),
                             E265_05=mean(as.numeric(E265_05),na.rm=TRUE),
                             E265_08=mean(as.numeric(E265_08),na.rm=TRUE),
                             E265_09=mean(as.numeric(E265_09),na.rm=TRUE),democ=max(democ)),by="S025"]

covs_logs<-c("E265_01", "E265_02",  "E265_04", 
             "E265_05",  "E265_08", "E265_09")
countries$E236<-round(countries$E236,1)

countries[, (covs_logs) := round(.SD,2)*100, .SDcols = covs_logs]
countries<-countries[order(S025)]
countries<-countries[order(democ)]

countries$democ=NULL
names(countries)<-c("Country","Level of Democracy in Country (1-10)","Votes Counted Unfairly","Restrictions Placed on Opposition","Voters Bribed","Biased Media Coverage","Voters Threatened With Violence","Genuine Choice Not Available")

#### TABLE F2


wvs<-subset(wvs, democ==0)

wvs[wvs=="Not at all often"]<-1
wvs[wvs=="Not often" ]<-2
wvs[wvs=="Fairly often"]<-3
wvs[wvs=="Very often"]<-4


wvs$E265_01<-Recode(wvs$E265_01,"1=4;2=3;3=2;4=1")
wvs$E265_05<-Recode(wvs$E265_05,"1=4;2=3;3=2;4=1")
wvs$E265_09<-Recode(wvs$E265_09,"1=4;2=3;3=2;4=1")

wvs$E179WVS<-as.character(wvs$E179WVS)
wvs$E263<-as.character(wvs$E263)
wvs$E179WVS<-as.character(wvs$E179WVS)

### Nigeria
wvs$rulingparty[wvs$E179WVS=="NG: People's Democratic Party (PDP)"]<-1

### Malaysia
wvs$rulingparty[wvs$E179WVS=="MY: Barisan National (BN)"]<-1

### Azerbaijan
wvs$rulingparty[wvs$E179WVS=="AZ: New Azerbaijan Party"]<-1

### Ukraine
wvs$rulingparty[wvs$E179WVS=="UA: Partiya Regionov"]<-1

### Zimbabwe
wvs$rulingparty[wvs$E179WVS=="Zimbabwe African National Union Patriotic Front_ZANU PF"]<-1

### Kazakhstan
wvs$rulingparty[wvs$E179WVS=="KZ: People's and democratic party Nur Otan"]<-1

### Rwanda
wvs$rulingparty[wvs$E179WVS=="RW: Rwandan Patriotic Front (Front Patriotique Rwandais)"]<-1

### Singapore
wvs$rulingparty[wvs$E179WVS=="SG: PAP"]<-1

### Egypt ???????
wvs$rulingparty[wvs$E179WVS=="KZ: People's and democratic party Nur Otan"]<-1

### Yemen
wvs$rulingparty[wvs$E179WVS=="YE: GPC (General Popular Congress)"]<-1

### Algeria
wvs$rulingparty[wvs$E179WVS=="DZ: FLN ((Front de libération Nationale)"]<-1

### Jordan ???
wvs$rulingparty[wvs$E179WVS=="DZ: FLN ((Front de libération Nationale)"]<-1

### Fill in missing
wvs$rulingparty[is.na(wvs$rulingparty)==TRUE & wvs$E179WVS!="No answer;SG: Refused"]=0

### Demographics
wvs$male[wvs$X001=="Female"]<-0
wvs$male[wvs$X001=="Male"]<-1

wvs$S020<-as.character(wvs$S020)
wvs$X002<-as.character(wvs$X002)
wvs$X028<-as.character(wvs$X028)

wvs$age<-as.numeric(wvs$S020)-as.numeric(wvs$X002)
wvs$age[wvs$age>100 | wvs$age<18]<-NA

wvs$log_age<-log(wvs$age)

wvs$employed<-0
wvs$employed[wvs$X028=="Self employed" | wvs$X028=="Part time" | wvs$X028=="Full time"]<-1
wvs$employed[wvs$X028=="Don´t know" | wvs$X028=="No answer" | wvs$X028=="Not applicable" | wvs$X028=="Not asked in survey"]<-NA

wvs$class[wvs$X045=="Lower class"]<-1
wvs$class[wvs$X045=="Working class"]<-2
wvs$class[wvs$X045=="Lower middle class"]<-3
wvs$class[wvs$X045=="Upper middle class"]<-4
wvs$class[wvs$X045=="Upper class"]<-5

wvs$employed[wvs$X028=="Upper class"]<-1
wvs$employed[wvs$X028=="Don´t know" | wvs$X028=="No answer" | wvs$X028=="Not applicable" | wvs$X028=="Not asked in survey"]<-NA

wvs$education[wvs$X025=="Not applicable; No formal education"]<-1
wvs$education[wvs$X025=="Inadequately completed elementary education"]<-2
wvs$education[wvs$X025=="Completed (compulsory) elementary education"]<-3
wvs$education[wvs$X025=="Incomplete secondary school: technical/vocational type/(Comp"]<-4
wvs$education[wvs$X025=="Complete secondary school: technical/vocational type/Seconda"]<-5
wvs$education[wvs$X025=="Incomplete secondary: university-preparatory type/Secondary,"]<-6
wvs$education[wvs$X025=="Complete secondary: university-preparatory type/Full seconda"]<-7
wvs$education[wvs$X025=="Some university without degree/Higher education - lower-leve"]<-8
wvs$education[wvs$X025=="University with degree/Higher education - upper-level tertia"]<-9

wvs$townsize[wvs$X049=="2,000 and less"]<-1
wvs$townsize[wvs$X049=="2,000-5,000"]<-2
wvs$townsize[wvs$X049=="5,000-10,000"]<-3
wvs$townsize[wvs$X049=="10,000-20,000/10,000-25,000; EVS81:10M-25M"]<-4
wvs$townsize[wvs$X049=="20,000-50,000"]<-5
wvs$townsize[wvs$X049=="50,000-100,000"]<-6
wvs$townsize[wvs$X049=="100,000-500,000"]<-7
wvs$townsize[wvs$X049=="500,000 and more"]<-8

wvs$nationalvoted[wvs$E264=="Never"]<-1
wvs$nationalvoted[wvs$E264=="Usually"]<-2
wvs$nationalvoted[wvs$E264=="Always"]<-3

est1<-felm(E236 ~ male + log_age + education + townsize + class + employed + nationalvoted + rulingparty | factor(S025) | 0 | S025, data=wvs)

est2<-felm(E265_01 ~ male + log_age + education + townsize + class + employed + nationalvoted + rulingparty | factor(S025) | 0 | S025, data=wvs)

est3<-felm(E265_02 ~ male + log_age + education + townsize + class + employed + nationalvoted + rulingparty | factor(S025) | 0 | S025, data=wvs)

est4<-felm(E265_04 ~ male + log_age + education + townsize + class + employed + nationalvoted + rulingparty | factor(S025) | 0 | S025, data=wvs)

est5<-felm(E265_05 ~ male + log_age + education + townsize + class + employed + nationalvoted + rulingparty | factor(S025) | 0 | S025, data=wvs)

est6<-felm(E265_08 ~ male + log_age + education + townsize + class + employed + nationalvoted + rulingparty | factor(S025) | 0 | S025, data=wvs)

est7<-felm(E265_09 ~ male + log_age + education + townsize + class + employed + nationalvoted + rulingparty | factor(S025) | 0 | S025, data=wvs)





